﻿using System.Windows;
using System.Windows.Controls;
using XamlaApp.ViewModels;

namespace XamlaApp.Views.ElementPropertyViews
{
    public partial class ImagePropertyView : UserControl
    {
        private ImageViewModel _vm;
        public ImageViewModel VM
        {
            get { return _vm; }
            set { _vm = value;
                DataContext = _vm;}
        }
        
        public ImagePropertyView()
        {
            InitializeComponent();
            Loaded += ImagePropertyView_Loaded;
        }

        void ImagePropertyView_Loaded(object sender, RoutedEventArgs e)
        {
            ChangeImage += VM.LoadImageFromFileSystem;
        }

        //the button is in a datatemplate so we have to bubble it to an event that can be exposed in code-behind
        private void btnChangeImage_Click(object sender, RoutedEventArgs e)
        {
            if (ChangeImage != null) ChangeImage(this, e);
        }

        public event RoutedEventHandler ChangeImage;
    }
}
